package com.djhu.freepartner.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.djhu.freepartner.bean.PartnerConsumeRecord;
import com.djhu.freepartner.core.constant.ConsumeType;
import com.djhu.freepartner.dao.PartnerConsumeRecordMapper;
import com.djhu.freepartner.service.IPartnerConsumeRecordService;
import com.djhu.freepartner.service.model.BonuspointSearchModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 消费记录 服务实现类
 * </p>
 *
 * @author zw
 * @since 2018-08-01
 */
@Service
public class PartnerConsumeRecordServiceImpl extends ServiceImpl<PartnerConsumeRecordMapper, PartnerConsumeRecord> implements IPartnerConsumeRecordService {


    @Override
    public Page<PartnerConsumeRecord> selectConsumerLogByPage(BonuspointSearchModel searchModel) {
        Wrapper wrapper = transfer(searchModel);
        Page page = new Page(searchModel.getPagenum(),searchModel.getPagesize());
        return this.selectPage(page,wrapper);
    }

    private Wrapper transfer(BonuspointSearchModel searchModel) {
        Wrapper wrapper = new EntityWrapper<PartnerConsumeRecord>();
        wrapper.eq("userid",searchModel.getUserid());
        if (searchModel.getType().equals(0)){

        }else if (searchModel.getType().equals(ConsumeType.CONSUME.getCode())){
            wrapper.eq("consumesource","1");
        }else if (searchModel.getType().equals(ConsumeType.RECHARGE.getCode())){
            wrapper.eq("consumesource","2");
        }

        if (StringUtils.isNotEmpty(searchModel.getStartdate())){
            wrapper.gt("consumedate",searchModel.getStartdate());
        }
        if (StringUtils.isNotEmpty(searchModel.getEnddate())){
            wrapper.lt("consumedate",searchModel.getEnddate());
        }
        return wrapper;
    }

    @Override
    public List<PartnerConsumeRecord> selectConsumerLog(BonuspointSearchModel searchModel) {
        Wrapper wrapper = transfer(searchModel);
        return this.selectList(wrapper);
    }
}
